#coding=utf-8

PREBASE_XML = """
<base_xml>
    <source>HIS</source>
    <hosp_code>{hosp_code}</hosp_code>
    <dept_code>{dept_code}</dept_code>
    <dept_name>{dept_name}</dept_name>
    <doct>
        <code>{doct_code}</code>
        <name>{doct_name}</name>
        <type></type>
    </doct>
    <hosp_id>{hosp_code}</hosp_id>
</base_xml>
"""

PRESCRIPTION_XML = """
<details_xml is_upload='{checktype}'>
    <his_time>{his_time}</his_time>
    <hosp_flag>{hosp_flag}</hosp_flag>
    <treat_type>{treat_type}</treat_type>
    <treat_code>{treat_code}</treat_code>
    <bed_no>{bed_no}</bed_no>
    <area_code>{area_code}</area_code>
    <patient>
        <name>{name}</name>
        <birth>{birth}</birth>
        <sex>{sex}</sex>
        <weight>{weight}</weight>
        <height>{height}</height>
        <id_card>{id_card}</id_card>
        <card_type>{card_type}</card_type>
        <card_code>{card_code}</card_code>
        <pregnant_unit>{pregnant_unit}</pregnant_unit>
        <pregnant>{pregnant}</pregnant>

        <allergic_data>{allergic_data}</allergic_data>
        <diagnose_data>{diagnose_data}</diagnose_data>
    </patient>
    <prescription_data>
        <prescription>
            <id>{id}</id>
            <reason>{reason}</reason>
            <is_urgent>0</is_urgent>
            <is_new>{is_new}</is_new>
            <is_current>{is_current}</is_current>
            <doct_code>{doct_code}</doct_code>
            <doct_name>{doct_name}</doct_name>
            <dept_code>{dept_code}</dept_code>
            <dept_name>{dept_name}</dept_name>
            <pres_type>{pres_type}</pres_type>
            <pres_time>{pres_time}</pres_time>

            <medicine_data>{medicine_list}</medicine_data>
        </prescription>
    </prescription_data>
</details_xml>
"""

MEDICINESDATA = """
<medicine>
    <name>{name}</name>
    <his_code>{his_code}</his_code>
    <insur_code>{insur_code}</insur_code>
    <pyd_code></pyd_code>
    <link_group></link_group>
    <spec>{spec}</spec>
    <group>{group}</group>
    <reason>{reason}</reason>
    <dose_unit>{dose_unit}</dose_unit>
    <dose>{dose}</dose>
    <ord_uom>{ord_uom}</ord_uom>
    <ord_qty>{ord_qty}</ord_qty>
    <freq>{freq}</freq>
    <administer>{administer}</administer>
    <begin_time>{begin_time}</begin_time>
    <end_time>{end_time}</end_time>
    <days>{days}</days>
</medicine>
"""

DIAGNOSEDATA = """
    <diagnose>
        <type>{type}</type>
        <name>{name}</name>
        <code>{code}</code>
    </diagnose>
"""

# MQ_DT_CFMX
MQ_DT_CFMX = """
SELECT id, is_new, is_current, doct_code, doct_name, dept_code, dept_name,
       pres_type, pres_time, name, his_code, insur_code, pyd_code, link_group,
       spec, ypzh, reason, dose_unit, dose, ord_qty, ord_uom, freq, administer,
       begin_time, end_time, jzxh, days, ypdj, ypcd, ybmlmc, yplx, brid, brkh, cfyblx, 
       cflb, tsyp, (select sum(ord_qty*ypdj) from MQ_DT_CFMX where id = '%s') as totalprice, 
       freq_name, administer_name, bzdw 
FROM MQ_DT_CFMX WHERE id='%s'
"""

# MQ_DT_BASE
MQ_DT_BASE = """
SELECT his_time, hosp_flag, treat_type, treat_code,
       lis_adm_no, bed_no, area_code,
       name, is_infant, birth, sex, weight, height,
       sfzh, card_type, pregnant_unit, pregnant, mzhm, ybkh, 
       (case when is_infant is not null then '6' when pregnant is not null then '1' else '' end) as tsrqtype 
FROM MQ_DT_BASE WHERE treat_code='%s'
"""

# 门诊诊断
MQ_MZ_JBZD = """
select * from mq_mz_jbzd where jzxh = '%s'
"""

# lis 检验
SQL_GetLIS = """
select b.[报告ID] as lisno, b.[报告时间] as reporttime, 
a.[申请项目名称] as lisname, b.[报告项目名称] as name, 
b.[报告项目代码] as code, b.[检验结果] as value, 
b.[结果单位] as unit, b.[结果标志] as result, 
b.[参考范围] as range 
from [接口视图_申请单明细表] a
left join 
[接口视图_检验报告结果] b on
a.[申请单ID] = b.[申请单ID] 
where b.[病人ID] = '%s' order by b.[报告ID]
"""

# pacs检查
SQL_GetPACS = """
select [ReportID] as pacsno, [InsertDate] as reporttime, 
[STUDY_INS_UID] as patientid, [REQ_PROC_ID] as studyid, 
[ALLDIRECTION] as name, [CONTENTTWO] as value, 
[CONTENTTHREE] as result 
from [PACSREPORT] where [ADM_ID] = '%s' 
"""